package com.bjsxt.string;


public class test {
    public static void main(String[] args) {
        String str1 = new String("abcdef");
        String str2 = new String("abcdef");
        System.out.println(str1==str2);
        System.out.println(str1.equals(str2));

        System.out.println(str1.length());
        System.out.println(str1.charAt(str1.length()-1));
        String str3 = new String("AbcDef");
        System.out.println(str1.equals(str3));
        System.out.println(str1.equalsIgnoreCase(str3));
        String str4 = "def";
        System.out.println(str2.indexOf("def"));
        System.out.println("abcdefgdef".lastIndexOf("def"));
        String str5 = "abcdef".replace("cd","D");
        System.out.println(str5);
        System.out.println("abcdefg".startsWith("abc"));
        System.out.println("abcdefg".endsWith("abc"));
        System.out.println("abcdefg".substring(2,4));
        System.out.println("abcdefg".substring(3));
        System.out.println("abCdeFg".toLowerCase());
        System.out.println("abCdeFg".toUpperCase());
        System.out.println("  a b  ".length());
        System.out.println("  a b  ".trim());
        System.out.println("  a b  ".replace(" ",""));

        StringBuilder str6  = null;
        StringBuffer str7 = null;
        str7 = new StringBuffer("gao");
        str7.append("lao").append("dfg");
        str7.insert(0,'s');
        System.out.println(str7);
        str7.deleteCharAt(0);
        System.out.println(str7);

        String str8 = "";
        long num1 = Runtime.getRuntime().freeMemory();
        long time1 = System.currentTimeMillis();
        for (int i = 0;i<5000;i++){
            str8 += i;
        }
        long num2 = Runtime.getRuntime().freeMemory();
        long time2 = System.currentTimeMillis();
        System.out.println(num1-num2);
        System.out.println(time2-time1);

        StringBuilder str9 = new StringBuilder("");
        long num3 = Runtime.getRuntime().freeMemory();
        long time3 = System.currentTimeMillis();
        for (int i = 0;i<5000;i++){
            str9.append(i);
        }
        long num4 = Runtime.getRuntime().freeMemory();
        long time4 = System.currentTimeMillis();
        System.out.println(num3-num4);
        System.out.println(time4-time3);
    }
}
